//
//  RETProductNameCell.m
//  Retail
//
//  Created by ChenJie on 4/1/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import "RETProductNameCell.h"
#import "OABase.h"

typedef NS_ENUM(NSUInteger, ComponentId) {
    TitleLabel = 1,
    Separator,
};

@interface RETProductNameCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIView *separator;

@end

@implementation RETProductNameCell

#pragma mark - Lifecycle methods

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.separator];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    //
    self.titleLabel.frame = [self.viewModel.oa_layouts[@(TitleLabel)] CGRectValue];
    self.separator.frame = [self.viewModel.oa_layouts[@(Separator)] CGRectValue];
}

- (void)prepareForReuse {
    [super prepareForReuse];
    
    //
}

#pragma mark - Public methods

//#define kMarginLeft 112
//#define kMarginRight 67
//#define kSpaceBetween 69
//#define kRelatedProductWidth 145

#define kTitleMarginTop 20
#define kSeparatorMarginTop 35
#define kSeparatorHeight 1
#define kTitleFont [UIFont systemFontOfSize:24]

+ (CGFloat)oa_heightWithWidth:(CGFloat)cellWidth viewModel:(RETProductNameCellViewModel *)viewModel {
    NSMutableDictionary *layouts = [NSMutableDictionary dictionary];
    
    CGFloat topMark = 0;
    
    topMark += kTitleMarginTop;
    CGSize titleSize = [viewModel.title oa_sizeWithWidth:cellWidth font:kTitleFont];
    CGRect titleFrame = CGRectMake(0, topMark, titleSize.width, titleSize.height);
    layouts[@(TitleLabel)] = OAValueWithRect(titleFrame);
    topMark += titleSize.height;
    
    topMark += kSeparatorMarginTop;
    CGRect separatorFrame = CGRectMake(0, topMark, cellWidth, kSeparatorHeight);
    layouts[@(Separator)] = OAValueWithRect(separatorFrame);
    
    viewModel.oa_layouts = layouts;
    
    return CGRectGetMaxY(separatorFrame);
}

#pragma mark - Private methods



#pragma mark - Event response methods



#pragma mark - Delegate methods



#pragma mark - Setter

- (void)setViewModel:(RETProductNameCellViewModel *)viewModel {
    _viewModel = viewModel;
    
    self.titleLabel.text = viewModel.title;
}

#pragma mark - Getter

OAGetLabel(titleLabel, ^(UILabel *label){
    label.textColor = OAColor(000000);
    label.font = kTitleFont;
    label.numberOfLines = 0;
})

OAGetView(separator, ^(UIView *view){
    view.backgroundColor = OAColor(dddddd);
})

#pragma mark - Memory Management Methods

- (void)dealloc {
}

@end
